import batchTag from '../../component/batchTag'

export default {
  components: {
    batchTag
  },
  props: {
    display: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      tabEdit: false,
      selections: [],
      // tableData: [{
      //     date: '2016-05-02',
      //     type: '演员',
      //     long: '50分钟',
      //     name: '张国立',
      //     address: '《纪晓岚》'
      //   },
      //   {
      //     date: '2016-05-04',
      //     type: '合唱团',
      //     long: '50分钟',
      //     name: '大江大河合唱团',
      //     address: '《黄河大合唱》'
      //   },
      //   {
      //     date: '2016-05-01',
      //     type: '诗朗诵',
      //     long: '50分钟',
      //     name: '李白',
      //     address: '《蜀道难》'
      //   },
      //   {
      //     date: '2016-05-03',
      //     type: '主持人',
      //     long: '50分钟',
      //     name: '杜甫',
      //     address: '《茶话会》'
      //   },
      //   {
      //     date: '2016-05-03',
      //     long: '50分钟',
      //     type: '舞美',
      //     name: '文天祥',
      //     address: '《破阵子》'
      //   }
      // ],
      pagination: {
        page: 1,
        size: 10,
        total: 100
      },
      searchText: ''
    }
  },
  computed: {
    visible: {
      set(v) {
        this.$emit('update:display', v)
      },
      get() {
        return this.display
      }
    }
  },
  methods: {
    handleEdit(obj, type) {
      // this.visible = true
      if (this.tabEdit) {
        this.handleCancel()
      }
      this.$emit('handle-edit', {
        data: {
          ...obj,
          min: Math.floor(obj.startTime / 60),
          sec: obj.startTime % 60
        },
        type: type
      })
    },
    handleSizeChange(v) {},
    handleCurrentChange(v) {},
    handleSelectionChange(array) {
      this.selections = array
    },
    handleDelete() {
      this.$confirm('删除所选项, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.delete) this.delete()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    handleAdd() {
      if (!this.tabEdit) {
        this.tabEdit = true
        this.tableData.push({
          editRow: true
        })
      }
    },
    handleSave() {
      if (this.submitSimpleActor) this.submitSimpleActor()
      if (this.submitProgram) this.submitProgram()
      if (this.submitPart) this.submitPart()
      this.emptyForm()
    },
    handleCancel() {
      this.emptyForm()
    },
    emptyForm() {
      this.resetForm()
      this.tabEdit = false
      this.tableData.pop()
    },
    resetForm() {
      Object.keys(this.addObj).forEach(k => {
        if (typeof this.addObj[k] === 'boolean') {
          this.addObj[k] = false
        } else {
          this.addObj[k] = ''
        }
      })
    }
  }
}
